<template>
  <div class="gdap-history" scroll="no">
    <el-row>
      <el-col :span="2">
        <el-button type="success" round icon="el-icon-back" @click="gohome">
        返回首页
      </el-button>
      </el-col>
      <el-col :span="20">
     <p style="  font-family:SiYuanBold;color:rgb(207, 139, 50);font-size:30px;text-align: center;">推荐纪录</p>
      </el-col>
    </el-row>
    

     <!-- <p style="color: rgb(187, 187, 187); min-width: 10px; min-height: 10px;font-family: Oswald;ont-size: 12px;text-align: center;">RECOMMENDATION RECORD</p> -->
    <el-tabs tab-position="center" style="width:80%;margin:0 auto">
      <!-- <el-tab-pane label="推荐记录"> -->
        <el-form :inline="true" :model="fromLineRecommd" style="text-align:center">
          <!-- <el-form-item label="考号">
            <el-input placeholder="请输入考号" v-model="fromLineRecommd.userCode"></el-input>
          </el-form-item> -->
          <el-form-item label="地域">
            <el-input placeholder="地域" v-model="fromLineRecommd.region"></el-input>
          </el-form-item>
          <el-form-item label="服务类型">
            <el-select placeholder="请选择" v-model="fromLineRecommd.type">
              <el-option label="正式推荐" value="0"></el-option>
              <el-option label="估分推荐" value="1"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="fnRecommSubmit" icon="el-icon-search">查询</el-button>
          </el-form-item>
        </el-form>
        <el-row>
          <el-col :span="24" style="height: 100%;">
            <el-table :data="recommHistoryList" style="width: 100%">
              <el-table-column type="index" >
              </el-table-column>
              <el-table-column prop="operTime" label="时间" :formatter="timestampToTime" >
              </el-table-column>
              <el-table-column prop="yzmc" label="语种" >
              </el-table-column>
              <el-table-column prop="klmc" label="科类" >
              </el-table-column>
              <el-table-column prop="zf" label="总分" >
              </el-table-column>
                   <el-table-column prop="px" label="排名" >
              </el-table-column>
              <el-table-column prop="areaChoice" label="地域条件" width="120%">
              </el-table-column>
              <el-table-column prop="zyChoiceName" label="专业条件" width="200%">
              </el-table-column>
              <el-table-column prop="recNumber" label="数量" >
              </el-table-column>
              <el-table-column prop="isExperience" label="服务类型" >
                <template slot-scope="scope">
                  {{scope.row.isExperience*1==0?'正式推荐':'估分推荐'}}
                </template>
              </el-table-column>
              <el-table-column label="操作" >
                <template slot-scope="scope">
                  <el-button type="text" size="small" @click="recommendReason(scope)">查看</el-button>
                </template>
              </el-table-column>
            </el-table>

          </el-col>

          <el-col :span="24" style="margin:3%;text-align:center; padding-bottom:10vh;">
            <el-pagination v-if="recommTotaCount!=''" @current-change="pageChangedRecomm" :current-page.sync="currentPageRecom"
              :page-size="listNumRecom" layout="total, prev, pager, next" :total="recommTotaCount">
            </el-pagination>
          </el-col>
        </el-row>

      <!-- </el-tab-pane> -->
      <!-- <el-tab-pane label="预测记录">
        <el-form :inline="true" :model="fromLinePredicted" style="margin-top:8px">
          <el-form-item label="考号">
            <el-input placeholder="请输入考号" v-model="fromLinePredicted.userCode"></el-input>
          </el-form-item>
          <el-form-item label="院校名称">
            <el-input placeholder="请输入院校名称" v-model="fromLinePredicted.universName"></el-input>
          </el-form-item>
          <el-form-item label="服务类型">
            <el-select placeholder="请选择" v-model="fromLinePredicted.type">
              <el-option label="正式推荐" value="0"></el-option>
              <el-option label="估分推荐" value="1"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="fnPredictedSubmit" icon="el-icon-search">查询</el-button>
          </el-form-item>
        </el-form>

                <el-row>
          <el-col :span="24" style="height: 100vh;overflow-y: auto;">
            <el-table :data="predictedHistroyList"  style="width: 100%">
              <el-table-column type="index" width="50">
              </el-table-column>
              <el-table-column prop="ksh" label="考号">
              </el-table-column>
              <el-table-column prop="yzmc" label="语种" width="70">
              </el-table-column>
              <el-table-column prop="klmc" label="科类" width="50">
              </el-table-column>
              <el-table-column prop="zf" label="总分" width="50">
              </el-table-column>
              <el-table-column prop="zyChoiceName" label="专业">
              </el-table-column>
              <el-table-column prop="yx" label="院校">
              </el-table-column>
              <el-table-column prop="operTime" label="时间">
              </el-table-column>
              <el-table-column prop="isExperience" label="服务类型" width="100">
                <template slot-scope="scope">
                  {{scope.row.isExperience*1==0?'正式推荐':'估分推荐'}}
                </template>
              </el-table-column>
              <el-table-column label="操作" width="50">
                <template slot-scope="scope">
                  <el-button type="text" size="small">查看</el-button>
                </template>
              </el-table-column>
            </el-table>

          </el-col>

          <el-col :span="24" style="margin-top:3%;text-align:center">
            <el-pagination v-if="predictedTotaCount!=''" @current-change="pageChangedPredicted" :current-page.sync="currentPagePredicted"
              :page-size="listNumPredicted" layout="total, prev, pager, next" :total="predictedTotaCount">
            </el-pagination>
          </el-col>
        </el-row>
      </el-tab-pane> -->
    </el-tabs>
  </div>
</template>
<script>
  import api from '@/utils/api'
  export default {
    data() {
      return {
        //推荐记录相关
        fromLineRecommd: {
          userCode: '',
          region: '',
          type: ''
        },
        recommHistoryList: [],
        recommTotaCount: '',
        currentPageRecom: 1,
        listNumRecom: 10,
        //预测记录相关
        fromLinePredicted: {
          userCode: '',
          universName: '',
          type: ''
        },
        predictedHistroyList: [],
        predictedTotaCount: '',
        currentPagePredicted: 1,
        listNumPredicted: 10,
      }
    },
    methods: {
            gohome(){
         this.$router.push('/');
      },
      // 时间戳转换成时间
      timestampToTime (row, column) {
        var date = new Date(row.operTime) //时间戳为10位需*1000，时间戳为13位的话不需乘1000
        var Y = date.getFullYear() + '-'
        var M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-'
        var D = date.getDate() + ' '
        var h = date.getHours() + ':'
        var m = date.getMinutes() + ':'
        var s = date.getSeconds()
        return Y+M+D+h+m+s
    },
      //推荐记录 查询历史 相关
      fnRecommend(startNum, listNum) {
        var searchConditionArray = new Array();
        searchConditionArray.push({
          constraint: 'EQUALS',
          fieldName: 'userId',
          fieldValue: '13565869085',
          inputType: 'input'
        });
        if (this.fromLineRecommd.userCode !== '' && this.fromLineRecommd.userCode !== 'undefined') {
          searchConditionArray.push({
            constraint: 'EQUALS',
            fieldName: 'ksh',
            fieldValue: this.fromLineRecommd.userCode,
            inputType: 'input'
          });
        }
        if (this.fromLineRecommd.type !== '' && this.fromLineRecommd.type !== 'undefined') {
          searchConditionArray.push({
            constraint: 'EQUALS',
            fieldName: 'isExperience',
            fieldValue: this.fromLineRecommd.type,
            inputType: 'input'
          });
        }
        if (this.fromLineRecommd.region !== '' && this.fromLineRecommd.region !== 'undefined') {
          searchConditionArray.push({
            constraint: 'LIKE',
            fieldName: 'areaChoice',
            fieldValue: this.fromLineRecommd.region,
            inputType: 'input'
          });
        }
        const params = "searchCond=" + JSON.stringify(searchConditionArray) +
          '&start=' + (1 + listNum * (startNum - 1)) + '&num=' + listNum;
        api({
            url: '/nceeSysMgr/rest/data/searchByCond/RecHisRecord',
            method: 'post',
            data: params
          })
          .then(res => {
            if (res.status == 200) {
              this.recommHistoryList = res.data
            }
          })
          .catch(e => {
            console.error(e)
          })
        //获取当前条件下的所有数据的总数
        api({
            url: '/nceeSysMgr/rest/data/searchCountByCond/RecHisRecord',
            method: 'post',
            data: params
          })
          .then(res => {
            if (res.status == 200) {
              this.recommTotaCount = res.data.count
            }
          })
          .catch(e => {
            console.error(e)
          })

      },
      //推荐记录 分页方法
      pageChangedRecomm() {
        this.fnRecommend(this.currentPageRecom, this.listNumRecom)
      },
      //推荐记录查询按钮
      fnRecommSubmit() {
        this.currentPageRecom = 1;
        this.fnRecommend(this.currentPageRecom, this.listNumRecom)
      },
      //预测记录 查询历史 相关
      fnPredicted(startNum, listNum) {
        var searchConditionArray = new Array();
        searchConditionArray.push({
          constraint: 'EQUALS',
          fieldName: 'userId',
          fieldValue: '13565869085',
          inputType: 'input'
        });
        if (this.fromLinePredicted.userCode !== '' && this.fromLinePredicted.userCode !== 'undefined') {
          searchConditionArray.push({
            constraint: 'EQUALS',
            fieldName: 'ksh',
            fieldValue: this.fromLinePredicted.userCode,
            inputType: 'input'
          });
        }
        if (this.fromLinePredicted.type !== '' && this.fromLinePredicted.type !== 'undefined') {
          searchConditionArray.push({
            constraint: 'EQUALS',
            fieldName: 'isExperience',
            fieldValue: this.fromLinePredicted.type,
            inputType: 'input'
          });
        }
        if (this.fromLinePredicted.universName !== '' && this.fromLinePredicted.universName !== 'undefined') {
          searchConditionArray.push({
                constraint:'LIKE',
                fieldName:'yx',
                fieldValue:this.fromLinePredicted.universName,
                inputType:'input'
            });
        }
        const params = "searchCond=" + JSON.stringify(searchConditionArray) +
          '&start=' + (1 + listNum * (startNum - 1)) + '&num=' + listNum;
        api({
            url: '/nceeSysMgr/rest/data/searchByCond/PredictionRecord',
            method: 'post',
            data: params
          })
          .then(res => {
            if (res.status == 200) {
              this.predictedHistroyList = res.data
            }
          })
          .catch(e => {
            console.error(e)
          })
        //获取当前条件下的所有数据的总数
        api({
            url: '/nceeSysMgr/rest/data/searchCountByCond/PredictionRecord',
            method: 'post',
            data: params
          })
          .then(res => {
            if (res.status == 200) {
              this.predictedTotaCount = res.data.count
            }
          })
          .catch(e => {
            console.error(e)
          })
      },
      //预测记录 分页方法
      pageChangedPredicted() {
        this.fnPredicted(this.currentPagePredicted, this.listNumPredicted)
      },
      //预测记录 查询按钮
      fnPredictedSubmit() {
        this.currentPagePredicted = 1;
        this.fnPredicted(this.currentPagePredicted, this.listNumPredicted)
      },

      recommendReason(scope) {
        console.log(scope)
        const params = {
          areaSet: scope.row.areaChoice,
          kldm: scope.row.kldm,
          px: scope.row.px,
          yzmc: scope.row.yzmc,
          zf: scope.row.zf,
          zyList: scope.row.zyChoice,
          userId: scope.row.userId
        }
        localStorage.setItem('estimateparam', JSON.stringify(params))
        this.$router.push('/result')
      }
    },
    mounted() {
      this.fnRecommend(1, 10)
      // this.fnPredicted(1,10)
    },
  }
</script>
<style>
  .gdap-history {
    padding: 12px;
    width: 70%;
    margin: 5px auto;
    overflow-x: hidden;
    background-color:#fff;
  }
</style>